package com.shengwei.truck.driver.view.adapter.mine;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.shengwei.truck.driver.R;
import java.util.List;

/**
 * 显示车辆牌号列表的配器
 */
public class CarNumsAdapter extends BaseAdapter {
    private List<String> mCarNums;
    private Context mContext;

    private LayoutInflater mInflater;
    public CarNumsAdapter(List<String> carNums, Context context) {
        mInflater = LayoutInflater.from(context);
        mCarNums = carNums;
        mContext = context;
    }
    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }
    @Override
    public int getCount() {
        if(mCarNums != null && mCarNums.size() > 0){
            return mCarNums.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return mCarNums.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        String carNum = mCarNums.get(position);
        MyViewHolder holder = null;
        if (convertView == null) {
            holder = new MyViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.car_nums_list_item, null);
            holder.tvCarNum = convertView.findViewById(R.id.tvCarNum);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }

        //填充列表项数据
        if(!TextUtils.isEmpty(carNum)){
            holder.tvCarNum.setText(carNum);
        }

        return convertView;
    }
    public static class MyViewHolder{
        TextView tvCarNum;
    }
}
